home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1710 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.8 KB  |  56 lines

  1. Newsgroups: comp.lang.c
  2. Path: gail.ripco.com!mambuhl
  3. From: mambuhl@ripco.com (Martin Ambuhl)
  4. Subject: Re: Splitting String ?   
  5. X-Nntp-Posting-Host: foley.ripco.com
  6. Message-ID: <DLA2BI.GsG@rci.ripco.com>
  7. Sender: usenet@rci.ripco.com (Net News Admin)
  8. Organization: Ripco Internet BBS Chicago
  9. Date: Tue, 16 Jan 1996 14:16:28 GMT
  10. X-Ident-Sender: mambuhl
  11.  
  12. jatmon@iag.net (John R Buchan)
  13. in <4dbnpf$47c@news.iag.net> wrote:
  14.  
  15. >In article <DL3u9M.9xt@rci.ripco.com>, mambuhl@ripco.com says...
  16. [snip]
  17. >->char *newname(char *s)
  18. >->{
  19. >->
  20. >->    char *dot;
  21. >->    dot = strchr(s, '.');
  22. >->    if (dot)
  23. >->        *dot = '\0';
  24. >->    strcat(s, ".UPD");
  25. >->    return s;
  26. >->}
  27.  
  28. >Unless I'm misssing something, this isn't going to work (safely or maybe at
  29. >all), if he passes in the same string literals.
  30.  
  31. Absolutely right.  I didn't make at all clear the point I meant to make.  As
  32. a result, I posted horrible code which is extremely dangerous.  I
  33. promise to be more straight-forward in the future.  In fact, as I
  34. re-read my message, I don't think I would have detected any irony.
  35. Sorry.
  36.  
  37. The unstated point was that the above code is the same functionally as
  38. the originally posted code with a lot of stuff that masked what he was
  39. doing removed.  Since the above code "does" exactly what the original
  40. code did and is clearly horrible, I thought it would be clear that he
  41. should rethink what he was doing.
  42.  
  43. For those unclear about what is going on,  when the above is called with
  44. a string literal, an attempt to change that literal is extremely
  45. dangerous since a) space has not been allocated and b) the literal need
  46. not be in writable memory.
  47.  
  48. >->>main() {
  49. >->> printf("%s\n",newname("LONGNAME.TXT"));
  50. >->> printf("%s\n",newname("NOEND")); >->>}
  51.  
  52.                            
  53. --
  54. * Martin Ambuhl       net: mambuhl@ripco.com
  55. * Chicago, IL (USA)    
  56.